mui.init({

});
var index_news;
mui.plusReady(function () {
    var self = plus.webview.currentWebview();
    index_news = new Vue({
        el: '#news_detail_list',
        data: {
            content_details:'',
        },
        mounted(){
            this.get_dDetail();
        },
        methods: {
            open_vip:function () {
                mui.openWindow({
                    url:'../memberVip.html',
                    createNew:false,
                });
            },
            get_dDetail:function () {
                get_news_content(self.newsid);
            },
            open_detail:function (id) {
                console.log(id);
                mui.openWindow({
		            url: 'detail.html',
                    extras: {
                        'newsid': id
                    },
                    show: {
                        autoShow: true,
                        aniShow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                        title: '加载中...',
                        options: {},
                    }
		        })
            }
        },
    })
})



function get_news_content(nid){
    var api_host = plus.storage.getItem('HOST_URL');
    mui.ajax({
        url:api_host+'/api/linxuan/news/getsubject',
        dataType:'json',
        data:{id:nid},
        type:'get',
        success:function(msg){
            if(msg.code == 1){
                index_news.content_details = msg.data;
                plus.nativeUI.closeWaiting();
                mui.currentWebview.show();
                $('body').animate({scrollTop:0},800);
            }else{
                mui.toast(msg.msg);
            }
        },
        error:function(xhr,type,errorThrown){
            console.log(errorThrown)
        }
    });
}

//分享
$('.share').on('tap', function() {
    $('.popMask').show();
    $('.popShare').slideDown(200);
});
$('.popMask ,.cancle_share').on('tap', function() {
    $('.popMask').hide();
    $('.popShare').slideUp(200);
});

//初始化下载对象
var dtask = null;
function createDownload(){
    //判断文件是否已经下载
    plus.io.resolveLocalFileSystemURL('_downloads/Snip_V2.0_5771.dmg',function(entry){
        if(entry.isFile){
            mui.toast('已经下载');
            //mui.alert(entry.fullPath);
        }
    },function(e){dBase();});
}

function dBase(){
    if(dtask){
        mui.toast('下载任务已经存在');
        return;
    }
    dtask = plus.downloader.createDownload(
        'http://snip.qq.com/resources/Snip_V2.0_5771.dmg',{method:'GET'},function(d,status){
            mui.toast(d.filename);
        });
    dtask.addEventListener("statechanged",function(task,status){
        if(!dtask){return;}
        switch(task.state){
            case 1: mui.toast('开始下载...');break;//开始
            case 2: mui.toast('链接到服务器...');break;//链接到服务器
            case 3:
                var progressVal = (task.downloadedSize/task.totalSize)*100;
                //mui('#bar').progressbar({progress:progressVal}).show();
                break;
            case 4: mui.toast('下载完成');break;
        }
    });
    dtask.start();
}
